\section*{\large Objectives}
\begin{normalsize}

The main objectives of this lab were to make the robot move straight, stop when it detects the first obstacle, go around it, move straight till the second and go back to starting position, as shown in Figure \ref{fig:lab1_ill}. Performing these objectives helped us to understand the basics of ROS and how to use sensors to improve robot control. You can watch our video at \url{https://www.youtube.com/watch?v=oyOBXJDm2Qc} and find our source code at \url{https://bitbucket.org/iaslab-unipd/robotics-labs-antonello-bardelle}.

\begin{figure}[!htb]
\centering
\includegraphics[scale=0.35]{./images/Robotica-Experience_1.png}
\caption{the main objectives \label{fig:lab1_ill}}
\end{figure}

\end{normalsize}

\section*{\large Algorithm overview}
\begin{normalsize}

\begin{figure}[!htb]
\centering
\includegraphics[scale=0.4]{./images/flowchart.png}
\caption{high-level flowchart \label{fig:flowchart}}
\end{figure}

% da descrivere nel dettaglio? Basta listare le funzioni nell'ordine di utilizzo
In the following, the descriptions of each function is given.

\end{normalsize}

\section*{\large Functions}
\begin{normalsize}

\begin{itemize}



\item \textbf{calibrateGyro}:
\begin{itemize}
	\item Inputs: 

	\begin{itemize}
		\item int samples: the number of samples;
		\item ros::Rate r: the desired rate to run at in Hz.
	\end{itemize}

	\item Description: mean and variance of the offset error of the gyroscope are computed over a number of samples, for example 200. It proved to be useful at the start and instead of sleeping before going back to starting position in order to correct gyro reads for greater accuracy.

\end{itemize}




		\item \textbf{goStraight}:
		\begin{itemize}
			\item Inputs: 

			\begin{itemize}
				\item ros::Publisher velocity\_pub: the publisher object to control the wheels speed;
				\item ros::Rate r: the desired spin rate to run at in Hz;
				\item double seconds: the number of seconds it will go straight.
			\end{itemize}

			\item Outputs: 

			\begin{itemize}
				\item double seconds: the effective number of seconds the robot has spent going straight.
			\end{itemize}		

			\item Description: the robot goes ahead until the time given expires or until it reaches the minimal range from the obstacle. If \emph{seconds} is left to zero, the robot goes ahead indefinitely until it reaches an obstacle. The linear speed is incrementally increased from zero to the desired value and the angular speed is set so to make the integration of the gyro reads equal to zero in order to make the robot go straight correcting motion errors dynamically.

		\end{itemize}





		\item \textbf{rotate}:
		
		\begin{itemize}
			\item Inputs: 

			\begin{itemize}
				\item ros::Publisher velocity\_pub: the publisher object to control the wheels speed;
				\item ros::Rate r: the desired spin rate to run at in Hz;
				\item double rad: the requested rotation angle  (positive if counterclockwise, negative if clockwise);
			\end{itemize}

			\item Outputs:
			
			\begin{itemize}
				\item double gyro\_integration: the effective rotation read by the gyroscope which may slightly differ from the requested angle.
			\end{itemize}

			\item Description: it makes the robot rotate by small increments until the rotation is complete. Integration of gyro reads allows to keep track of the subtended angle.

		\end{itemize}






\item \textbf{rotateHead}:
\begin{itemize}
	\item Inputs: 

	\begin{itemize}
		\item ros::Publisher head\_angle\_pub: the publisher object which allows messages publications;
		\item ros::Rate r:  the desired rate to run at in Hz;
		\item double angle: the rotation angle in degrees (positive if clockwise, negative if counterclockwise);
		\item double rotation\_time: the number of seconds to complete the rotation, default value is four.
	\end{itemize}

	\item Description: it rotates head by an angle.
\end{itemize}



\item \textbf{moveInCircle}:
\begin{itemize}
	\item Inputs: 

	\begin{itemize}
		\item ros::Publisher velocity\_pub: the publisher object which allows messages publications;
		\item ros::Rate r:  the desired rate to run at in Hz;
		\item double r: the radius of arc of circle;
		\item double rad: the length of the subtended angle in radians.
	\end{itemize}

	\item Outputs: 

	\begin{itemize}
		\item double gyro\_integration: the effective rotation read by the gyroscope;
	\end{itemize}

	\item Description: useful for making the robot go around the obstacle, the robot moves along an arc of circle of radius  \emph{r} with tangential velocity \emph{v} and angular velocity  \emph{w} such that $v = w * r$. Radius is kept constant by evaluating the distance from the obstacle (see \emph{rotateHead} and \emph{callbackUltrasonicSensor}) and adjusting the angular velocity. Integration of gyro reads allows to keep track of the subtended angle.
\end{itemize}



\end{itemize}

\end{normalsize}